package com.lscl.rabbitmq.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RedisTemplate redisTemplate;


    @GetMapping("/send/{messageId}")
    public String addOrders(@PathVariable String messageId) {

        MessageProperties prop = new MessageProperties();
        prop.setMessageId(messageId);
        Message message = new Message("测试幂等性".getBytes(), prop);

        // 发送消息
        rabbitTemplate.convertAndSend("test_queue", message);

        return messageId;
    }
}
